package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.feign.order.OrderFeignClient;
import com.atguigu.gmall.model.enums.OrderStatus;
import com.atguigu.gmall.model.order.entity.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class PaymentController {
    @Autowired
    OrderFeignClient orderFeignClient;


    @GetMapping("/pay.html")
    public String pay(@RequestParam Long orderId, Model model) {
        OrderInfo orderInfo = orderFeignClient.getOrderInfo(orderId).getData();

        if (orderInfo.getOrderStatus().equals(OrderStatus.UNPAID.name())) {
            model.addAttribute("orderInfo", orderInfo);
        } else {
            model.addAttribute("msg", "您当前订单的状态不是未付款！");

        }
        return "payment/pay";
    }

    @GetMapping("/weixin.html")
    public String weixin(@RequestParam String orderId,Model model) {
        model.addAttribute("orderId", orderId);
        return "payment/weixin";
    }


    @GetMapping("/pay/success.html")
    public String success() {
        return "payment/success";
    }
}
